package www.dashu.com.controller;

import org.springframework.data.domain.Page;
import www.dashu.com.api.CommonResult;
import www.dashu.com.domain.CProduct;
import www.dashu.com.domain.HomeContentResult;
import www.dashu.com.service.BAdsSwiperService;
import www.dashu.com.service.BCircleNavService;
import www.dashu.com.service.CProductService;
import www.dashu.com.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import www.dashu.com.service.base.QueryParams;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


/**
 * 首页内容管理Controller
 */
@Controller
@Api(tags = "HomeController", description = "首页内容管理")
@RequestMapping("/home")
public class HomeController {

    @Autowired
    TestService testService;
    @Autowired
    CProductService productService;
    @Autowired
    BCircleNavService circleNavService;
    @Autowired
    BAdsSwiperService swiperService;

    @ApiOperation("首页内容页信息展示")
    @RequestMapping(value = "/content", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<HomeContentResult> content() throws Exception
    {
        HomeContentResult contentResult = new HomeContentResult();
        QueryParams queryParams = new QueryParams();
        queryParams.setLimit(20);
        queryParams.setPage(1);
        queryParams.setSort("+id");

        Page<CProduct> pageData = productService.findAllIncludeColumn(Arrays.asList(ProductController.SHOW_COLUMN) ,queryParams);

        contentResult.setGoodsList(pageData.getContent());

        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("flag", "home");
        contentResult.setNav(circleNavService.findAll(queryMap));

        contentResult.setSwiper(swiperService.findAll(queryMap));

        return CommonResult.success(contentResult);
    }

    @ApiOperation("首页内容页信息展示")
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult test() {
        return testService.test();
    }

}
